package 线程安全;

import com.sun.xml.internal.bind.v2.model.core.ID;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 12066);

        InputStream inputStream = socket.getInputStream();
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("输入要发送的内容");
            String msg = sc.nextLine();
            if ("exit".equals(msg))
                break;
            OutputStream ots = socket.getOutputStream();
            ots.write(msg.getBytes());
            socket.shutdownOutput();
            int len = 0;
            System.out.println("server back!");
            while ((len = inputStream.read()) != -1) {
                System.out.println(new String(String.valueOf((len))));
            }
            System.out.println("finised!");
        }
        //ots.close();
        socket.close();
    }
}
